<template>
  <div>
    <el-card class="box-card">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getExportDispatchList()"
      class="dadeFrom"
    >
    <el-input v-model="dataForm.jobName" placeholder="真实名称" style="width: 200px"></el-input>
    <el-input v-model="dataForm.name" placeholder="工号" style="width: 200px"></el-input>  
    <el-select v-model="dataForm.mode" placeholder="推荐标签" clearable style="width: 200px">
      <el-option value="staffzh" label="管理人员"></el-option>
      <el-option value="empee_acct" label="一线人员"></el-option>
      <!-- <el-option
        v-for="option in lableList"
        :key="option.id"
        :label="option.dictName"
        :value="option.dictValue"
      >
      </el-option> -->
    </el-select>
    <el-button @click="searchData()" type="primary">查询</el-button>
    </el-form>
    </el-card>
    <el-card class="box-card" style="margin-top: 10px;">
      <!-- <el-button type="success" size="mini" @click="handleAdd()">添加标签</el-button> -->
      <el-table
        :data="dataList"
        style="width: 100%;margin-top: 20px;"
        @selection-change="handleSelectionChange"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(12,42,98, 0.9)"
      >
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
          type="index"
          label="序号"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="staffAccount"
          label="工号"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="staffName"
          label="真实姓名"
          align="center"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="orgName"
          label="部门"
          align="center"
        >
        </el-table-column> -->
        <el-table-column
          prop="telNum"
          label="联系方式"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="tagName"
          label="主数据群组标签"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="staffTag"
          label="小秘书标签"
          align="center"
        >
        </el-table-column>
        <!-- <el-table-column
          label="状态"
          align="center"
        >
        <template slot-scope="scope">
           {{scope.row.statusCd == 1000 ? '生效' : '失效'}}
        </template>
        </el-table-column> -->
        <!-- <el-table-column
          label="操作"
          align="center"
        >
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
        </template>
        </el-table-column> -->
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        :pageNum="pageNum" 
        :pageSize="pageSize" 
        @pageChange="pageChange"
      />
    </el-card>
    <!-- 弹窗, 新增 / 修改 -->
    <el-dialog
      title="添加标签"
      :visible.sync="dialogVisible"
      width="20%"
      >
      <div style="text-align: center;">
        <el-select v-model="lableVal" placeholder="选择标签">
          <el-option :label="item.dictName" :value="item.id" v-for="(item, index) in changeLableList" :key="index"></el-option>
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitSave()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      loading:true,
        dataList: [],
        pageNum: 1,
        pageSize: 10,
        total: 0,
        changeLableList: [],
        staffIds: [],
        dialogVisible:false,
        lableVal: '',
        lableList: [],
        dataForm: {
          jobName: '',
          name: '',
          mode: '',
        },

      }
  },
  created() {
    // this.fetchTableList()
    // this.fetchSelectData()
  },
  computed: {
    // lableList: {
    //   get () {
    //     return this.$store.state.type.du_user_tag
    //   }
    // },
  },
  activated: function () {
    this.fetchLableList()
    this.fetchTableList()
  },
  methods: {
    submitSave () {
      this.$http({
        url: this.$http.adornUrl('staffsysdictdata/saveDuStaffTag'),
        method: 'post',
        data: this.$http.adornData({
          staffIds: this.staffIds,
          tagId: this.lableVal
        })
      }).then(res => {
        if (res.data.code === 0) {
           this.$message({
            message: '添加成功',
            type: 'success'
          });
          this.dialogVisible = false
          this.fetchTableList()
        }
      })
    },
    handleAdd () {
      this.lableVal = ''
      this.dialogVisible = true
    },
    fetchLableList () {
      this.$http({
        url: this.$http.adornUrl('sysdictdata/list'),
        method: 'get',
        params: this.$http.adornParams({
          dictType: 'du_user_tag'
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.changeLableList = data.page.list
        }
      })
    },
    // 获取下拉框数据
    fetchSelectData () {
      this.$http({
        url: this.$http.adornUrl('sysdictdata/list'),
        method: 'get',
        params: this.$http.adornParams({
         dictType: 'send_type'
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.lableList = data.page.list
        }
      })
    },
    // 多选
    handleSelectionChange (val) {
      this.staffIds = []
      val.map((item) => {
        this.staffIds.push(item.staffId)
      })
    },
    // 点击搜索
    searchData () {
      this.fetchTableList()
    },
    // 获取表格数据
    fetchTableList () {
      this.loading = true
      const {jobName, name, mode} = this.dataForm
      this.$http({
        url: this.$http.adornUrl('/staff/staffList'),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageNum,
          limit: this.pageSize,
          staffName: jobName,
          staffAccount: name,
          staffTag: mode
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          setTimeout(()=>{
            this.loading = false
            this.total = data.page.totalCount
          this.dataList = data.page.list
          },1000)
          
        } else {
          this.$message.error(data.msg);
        }
      })
    },
   //编辑 
    handleEdit () {},
    // 删除
    handleDelete () {},
    // 再次提醒
    // 分页
    pageChange (page) {
      this.pageSize = page._pageSize;
      this.pageNum = page._currentPage;
      this.fetchTableList()
    }
  }
};
</script>
<style scoped>
</style>
